#include "stdafx.h"

#include "PosObject.h"



/*
 *	
 */
void PositionalObject::PointAt(const Vector3& target)
{
	Vector3 vdir;

	vdir = target-mPosition;

	double xangle = 0.0;
	double yangle = 0.0;

	mRotation.Identity();

	// y axis rotation first...
	if( vdir.z!=0.0f || vdir.x!=0.0f)
	{
		yangle = atan2(vdir.x,vdir.z);
	}

	// then rotate around x axis
	float len = vdir.Length();
	if(len!=0.0f)
	{
		xangle = -asin(vdir.y/len);
	}

	/*mRotation *= Quaternion(0.0f, (float)yangle, 0.0f);
	mRotation *= Quaternion((float)xangle, 0.0f, 0.0f);*/
	/*mRotation *= Quaternion().SetFromRadians(0.0,yangle,0.0);
	mRotation *= Quaternion().SetFromRadians(xangle,.0,.0);*/
	mRotation *= Quaternion().SetFromRadians(xangle,yangle,0.0);
}



void PositionalObject::Draw()
{
//	glPushMatrix();
	glTranslate(mPosition);
	glMultMatrix(mRotation.CreateMatrix());
//	glPopMatrix();
}